/////////////////////////////////////////////////////////////////////////
//
// Amuse Engine SDK - geometry
// Copyright( c) 2015.  All Rights Reserved
//
// File:		AEVertexDescriptor.cpp
// Author:		Gianluca Belardelli
// Date:		09/02/2015
//
/////////////////////////////////////////////////////////////////////////
#include <AEEngine.h>

void AEVertexDescriptor::SetFormatDefaults( void )
{
	// TODO: In teoria il metodo dovrebbe impostare i flag
	// di default per un vertex format di default.
	Reset();
}

AEBOOL32 AEVertexDescriptor::IsValidDescriptor( void ) const
{
	AEBOOL32 bRes = AEFALSE;
	for( AEINT32 i=0; i< AEMAX_MESHBUFFER_TEXCOORDS; i++ )
		bRes |= HasTexCoord(i);

	return bRes = HasPosition() || HasColor() || HasNormal() || HasSecondaryColor();
}

AEUINT32 AEVertexDescriptor::GetStreamMask( void ) const
{
	AEUINT32 uiStreamMask = 0;
	if( HasPosition() )
		uiStreamMask |= AEVERTEXSTREAM_POSITION;

	if( HasColor() )
		uiStreamMask |= AEVERTEXSTREAM_COLOR;

	if( HasNormal() )
		uiStreamMask |= AEVERTEXSTREAM_NORMAL;

	if( HasSecondaryColor() )
		uiStreamMask |= AEVERTEXSTREAM_SECONDARYCOLOR;

	for( AEINT32 i=0; i< AEMAX_MESHBUFFER_TEXCOORDS; i++ )
	{
		if( HasTexCoord( i ) )
			uiStreamMask |= ( 1 << (4+i) );
	}

	return uiStreamMask;
}

void AEVertexDescriptor::CopyVertices( void *lpDstBuffer, const AEVertexDescriptor &dstDesc, const void *lpSrcBuffer, const AEVertexDescriptor &srcDesc, AEINT32 nVertexCount )
{
}

AEINT32 AEVertexDescriptor::GetComponentCountForFormat( AEINT32 nFormat )
{
	switch( nFormat )
	{
		case AEVERTEXDESC_FORMAT_FLOAT: return 1;
		case AEVERTEXDESC_FORMAT_FLOAT2: return 2;
		case AEVERTEXDESC_FORMAT_FLOAT3: return 3;
		case AEVERTEXDESC_FORMAT_FLOAT4: return 4;
		case AEVERTEXDESC_FORMAT_BYTE4N: return 4;
		case AEVERTEXDESC_FORMAT_SHORT2N: return 2;
		case AEVERTEXDESC_FORMAT_SHORT4N: return 4;
		case AEVERTEXDESC_FORMAT_HALF2: return 2;
		case AEVERTEXDESC_FORMAT_HALF4: return 4;
		case AEVERTEXDESC_FORMAT_USHORT2N: return 2;
		case AEVERTEXDESC_FORMAT_USHORT4N: return 4;
		case AEVERTEXDESC_FORMAT_BYTE4: return 4;
		case AEVERTEXDESC_FORMAT_SHORT2: return 2;
		case AEVERTEXDESC_FORMAT_SHORT4: return 4;
	}

	return 0;
}

AEINT32 AEVertexDescriptor::GetComponentSizeForFormat( AEINT32 nFormat )
{
	switch( nFormat )
	{
		case AEVERTEXDESC_FORMAT_FLOAT: return 4;
		case AEVERTEXDESC_FORMAT_FLOAT2: return 8;
		case AEVERTEXDESC_FORMAT_FLOAT3: return 12;
		case AEVERTEXDESC_FORMAT_FLOAT4: return 16;
		case AEVERTEXDESC_FORMAT_BYTE4N: return 4;
		case AEVERTEXDESC_FORMAT_SHORT2N: return 4;
		case AEVERTEXDESC_FORMAT_SHORT4N: return 8;
		case AEVERTEXDESC_FORMAT_HALF2: return 4;
		case AEVERTEXDESC_FORMAT_HALF4: return 8;
		case AEVERTEXDESC_FORMAT_USHORT2N: return 4;
		case AEVERTEXDESC_FORMAT_USHORT4N: return 8;
		case AEVERTEXDESC_FORMAT_BYTE4: return 4;
		case AEVERTEXDESC_FORMAT_SHORT2: return 4;
		case AEVERTEXDESC_FORMAT_SHORT4: return 8;
	}
	return 0;
}

AEINT32 AEVertexDescriptor::GetAsFloatArray( const void *lpRawVertexData, AEINT32 nOfsAndFormat, AEFLOAT32 *lpDestFloat )
{
	return 0;
}

AEINT32 AEVertexDescriptor::SetAsFloatArray( void *lpRawVertexData, AEINT32 nOfsAndFormat, const AEFLOAT32 *lpSrcFloat )
{
	return 0;
}

void AEVertexDescriptor::ComputeHash( void )
{
}

AEBOOL32 AEVertexDescriptor::Equals( const AEVertexDescriptor &other ) const
{
	return AEFALSE;
}
